﻿///******************************************************    
///	FileName: Purchase.js
///	Action: 会员中心求购添加页面JS处理文件
///	Copyright(c)  2004-2008 Sirius Studio
///	Create Date: 2008-12-17
///	Rewriter:
///	Rewrite Date:
///******************************************************  
var rightIcon="../images/websen.gif"
var rightIcons="../../images/icon_nothing.gif";
var txtjbo=new  Array("ctl00_ContInfo_txtName","ctl00_ContInfo_txtKey","ctl00_ContInfo_txtBrand","ctl00_ContInfo_txtModel","ctl00_ContInfo_txtCount","ctl00_ContInfo_txtPrice")
//得到焦点
for(var i=0;i<txtjbo.length;i++){ $(txtjbo[i]).onfocus =function ()
{for (var j=0;j<txtjbo.length;j++)
{if (txtjbo[j]==event.srcElement.id){postobj(j);}}}}
function postobj(num)
{
obj = "txt"+num;
document.getElementById(obj).innerHTML =Purchase[num];
}
function oo(){$("yc").style.display="none"}
//失去焦点
for(var i=0;i<txtjbo.length;i++){ $(txtjbo[i]).onblur =function ()
{for (var j=0;j<txtjbo.length;j++)
{if (txtjbo[j]==event.srcElement.id){postobjs(j);}}}}
function postobjs(num)
{
  var obj="txt"+num;
if ($(obj).innerHTML!="")
  {$(obj).innerHTML=""}
else 
  {$(obj).innerHTML=ok;}
 
}
function getobj(objName){
   if ($) {
      return eval('$("'+ objName +'")');
   }else{
      return eval('document.all["'+ objName +'"]');
   }
}

$("ctl00_ContInfo_btnSave").onclick=function(){
 var Purases=new Array()
  var variale=0;
  var varrr=0;
   if(document.getElementById("ctl00_ContInfo_txtName").value.trim()==""){
      document.getElementById("txt0").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>产品名称不能为空</font>";
        variale=1;
    }
    if(document.getElementById("ctl00_ContInfo_txtKey").value.trim()=="")
    {
      document.getElementById("txt1").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>产品关键字不能为空</font>";
         variale=1;
    }
  
  if($("ctl00_ContInfo_txtCount").value!=""){
      if($("ctl00_ContInfo_txtCount").value==0){
      document.getElementById("txt4").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>需求数量不能为0</font>";
      varrr=1;
      }
      }else{
      
        document.getElementById("txt4").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>需求数量不能为空</font>";
        varrr=1;
      }
     
   if ($("ctl00_ContInfo_SortB").selectedIndex == -1) {
	         document.getElementById("txt10").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>请选择所属行业和产品类目！</font>";
	         variale=1;
    }
   else
    {
       document.getElementById("txt10").innerHTML="";
    }
     if($("ctl00_ContInfo_txtPrice").value!=0){
       if(!(rep.test($("ctl00_ContInfo_txtPrice").value))){ 
         document.getElementById("txt5").innerHTML="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>单价格式不正确</font>";
         varrr=1;
        }
      }else{
          document.getElementById("txt5").innerHTML="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>单价必须大于0小于9999999</font>";
          varrr=1;
      }
       if(variale!=0){
       window.location.href="#flagKeyword";
        return false; 
      }
      if(varrr!=0){
          window.location.href="#xiangxi";
          return false;
      }
      else
      {
           document.getElementById("txt10").innerHTML="";
           document.getElementById("txt5").innerHTML="";
           document.getElementById("txt4").innerHTML="";
         return true;
      }

   var flag=1;
   Purases[0]=Purchases(txtjbo[0],0,0)
   Purases[1]=Purchases(txtjbo[1],1,0)
   Purases[2]=Purchases(txtjbo[4],4,1)
   Purases[3]=Purchases(txtjbo[5],5,0)
   for (i=0;i<Purases.length;i++){
      if (Purases[i]==false){
         flag=0;
         break;
      } 
   } 
   if(flag==0){
      return false;
   }else
   {
     return true;
   }
}

//方法
function Purchases(name,num,bernum)
{
   var obj="txt"+num
   if($(name).value.replace(/\s/g,'')==""){
     $(obj).innerHTML=QgFb[num]
     return false;
   }else if(bernum==1){
      if (!isNumber(getobj(txtjbo[num]).value.replace(/\s/g,''))){
         $(obj).innerHTML=QgFb[6];
         return false 
      }else{
         $(obj).innerHTML=ok;
         return true
      } 
   }else{
      $(obj).innerHTML=ok;
      return true
   }
}

//显示信息
var ok="";
var title="<p>";
var titles="</p>"
var Purchase=new Array()
Purchase[0]=title+"产品名称中请勿出现规格、型号、品牌等内容。"+titles
Purchase[1]=title+"关键字用逗号隔开。例如：“超轻电脑桌,可折叠电脑桌”。"+titles
Purchase[2]=""
Purchase[3]=""
Purchase[4]=""
Purchase[5]=""

//求购信息
var QgFb=new Array(9);
QgFb[0]="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>产品名称不能为空</font>";
QgFb[1]="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>关键字不能为空</font>";
QgFb[2]="<font></font>";
QgFb[3]="<font></font>";
QgFb[4]="";
QgFb[5]="";
QgFb[6]="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>输入不符合规范,请输入数字!</font>";



var rep=/^(0|[1-9]\d*)(\.\d{1,2})?$/;
var reprice=new RegExp(rep);
$("ctl00_ContInfo_txtPrice").onblur=function(){
      if($("ctl00_ContInfo_txtPrice").value!=0){
        if(!(rep.test($("ctl00_ContInfo_txtPrice").value))){ 
            document.getElementById("txt5").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>单价格式不正确</font>";
            return false;
        }
        else{
            document.getElementById("txt5").innerHTML="";
            return true;
        } 
    }else
    {
     document.getElementById("txt5").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>单价必须大于0小于9999999</font>";
    }
}